import os
import cv2
import numpy as np
import shutil

def get_image_paths(directory):
    # 定義常見圖片格式
    image_extensions = (".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".webp")
    image_paths = []

    # 遍歷目錄及其子目錄
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.lower().endswith(image_extensions):  # 判斷是否是圖片
                image_paths.append(os.path.join(root, file))
    
    # 對結果進行排序
    image_paths.sort()  # 按完整路徑排序
    return image_paths


# path = '/media/ai/0bea6433-71ce-4bf1-a689-3b0348c3c57b/vslam/0423/965/results/mask'
# new_path = '/media/ai/0bea6433-71ce-4bf1-a689-3b0348c3c57b/vslam/0423/965/results/mask_index'
path = '/media/ai/0bea6433-71ce-4bf1-a689-3b0348c3c57b/vslam/0423/965/results/left_reproject_undistort_fisheye'
new_path = '/media/ai/0bea6433-71ce-4bf1-a689-3b0348c3c57b/vslam/0423/965/results/left_reproject_undistort_fisheye_index'
img_paths = get_image_paths(path)

for i, img_path in enumerate(img_paths):
    print(i)
    file_name_with_ext = os.path.basename(img_path)  # 提取文件名（带扩展名）
    file_id = os.path.splitext(file_name_with_ext)[0]  # 去掉扩展名，获取文件 ID
    new_name = file_id + "_" + str(i+1) + '.jpg'
    new_path1 = os.path.join(new_path, new_name)
    print(f'src {img_path}')
    print(f'dst {new_path}')
    shutil.copy(img_path, new_path1)
